<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>编辑商品</title>
    <link rel="stylesheet" href="/css/site.min.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
    <script src="/js/jquery-1.11.3.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/angular.js"></script>
</head>
<body>
<a href='javascript:void(0);' onclick="logOut()" class='close' style="float:right;margin-right:10%;width:8em;height:3em;padding-top: 8px;">退出</a>
<!--信息输入界面-->
<h2 style="text-align: center; color:#ff4d4d;">修改商品信息</h2>

<div class="container" style="margin-top: 95px;background-color:#ff4d4d;border-radius:10px;color: #000;">
    <form action="../../editProduct" method="post">
        <!--输入信息关键字段-->
        <div class="row">
            <div class="col-md-2 col-xm-2 col-xs-2">
                <!--areaId（区域编号，隐藏）-->
                <!--uid(商家编号，隐藏)-->
            </div>
            <div class="col-md-4 col-xs-4 col-xm-4">
                <!--payway-->
            </div>
            <div class="col-md-6 col-xs-6 col-sm-6">
                <!--total-->
            </div>
        </div>


        <!--输入信息关键字段-->
        <div class="row">
            <div class="col-md-3 col-xs-3 col-sm-3"></div>
            <!--name-->
            <div class="col-md-3 col-xs-3 col-sm-3"></div>
            <!--phone-->
            <div class="col-md-6 col-xs-6 col-sm-6"></div>
            <!--address-->
        </div>
        <span>商品信息</span>

        <div class="input">
            <div>
                <table class="table" style="border-collapse: collapse;margin-left:-15px;">
                    <thead>
                    <tr class="ui-widget-header ">
                        <th style="width:20%;padding-left: 6.5em">商品名:</th>
                        <th style="width: 20%;padding-left: 6.5em">规&nbsp;&nbsp;&nbsp;格:</th>
                        <th style="width: 20%;padding-left: 6.5em">单&nbsp;&nbsp;&nbsp;价:</th>
                        <th style="width: 20%;padding-left: 6.5em"></th>
                    </tr>
                    </thead>
                    <tbody id="tbodyspec">
                    <tr style="height: 1em">
                        <td style="width:20%"><input style="margin-left: 5em" type="text" class="pname" required
                                                     placeholder="商品名" value="<%=product.pName%>" /></td>
                        <td style="width:20%"><input style="margin-left: 5em" type="text" class="sname" required
                                                     placeholder="规格" value="<%=product.specName%>"  /></td>
                        <td style="width:20%"><input style="margin-left: 5em" type="text" class="price" required
                                                     placeholder="单价" value="<%=product.price%>" /></td>
                        <td style="width: 20%"></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <!--<a src="img/u58.png" id="addspec" type="button" value="增加一行输入框" style="cursor: pointer;height:40px;float: left;" class="btn btn-primary insertbutton close_1"/>添加</a>-->
        <input type="hidden"  name="productId"  value="<%=productId%>">
        <input id="hidProducts" name="productsInfo" type="hidden"/>
        <a class="btn  navbar-right close_1" style=" margin-right: 1%;margin-bottom: 1%;height:40px;"
           onclick="history.go(-1)" type="button" value="">返回</a>
        <input class="btn  navbar-right close_1" style=" margin-right: 1%;margin-bottom: 1%;height:40px;" onclick="return checkInputAndGetData()" type="submit"
           value="提交"/>
    </form>
</div>
<script>
    function checkInputAndGetData() {
        var products = "";
        var flag = true;
        $("#tbodyspec tr").each(function () {
            var pname = $(".pname", $(this)).val();
            var sname = $(".sname", $(this)).val();
            var price = $(".price", $(this)).val();
            if (pname != "" && sname != "" && price != "") {
                var regNum = /\d+(\.\d+)?$/;
                if (!regNum.test(price)) {
                    flag = false;
                    $(".price", $(this)).focus();
                    alert("价格应为数字类型");
                    return;
                }
                products += pname + "," + sname + "," + price + ";";
            } else {
                if (pname != "" || sname != "" || price != "") {
                    flag = false;
                    $(".pname", $(this)).focus();
                    alert("请完善光标所在行的数据或将该行删除");
                    return;
                }
            }
        })

        if (flag == false) {
            return false;
        }

        if (products.length > 1) {
            products = products.substring(0, products.length - 1);
            $("#hidProducts").val(products);
        }
    }
    function logOut() {
        top.location.href = "../../index/9999";
    }
</script>
</body>
</html>
